#include<iostream>
using namespace std;
#include<vector>
#include<sys/wait.h>
#include<functional>
#include<sys/types.h>
#include<unistd.h>
#include"task.h"
#include<cstdio>
typedef function<void()> task_t ;
void Loradtask(vector<task_t>& v)
{
    v.push_back(Print);
    v.push_back(Cout);
    v.push_back(Printf);
}
int main()
{
   vector<task_t>  v;
   Loradtask(v);

   pid_t id=fork();
   if(id==0)
   {
     int cnt=5;
      while(cnt)
      {
        cnt--;
        printf("我是子进程，pid：%d\n",getpid());
        sleep(1);

      }
      exit(0);
   }
       

    while(1)
    { 
    sleep(1);
     int status=0;
     pid_t rid=waitpid(id,&status,WNOHANG);
     printf("我是父进程，status id：%d\n",status);
     if(rid>0)
     {
       cout<<"suecess zuse"<<endl;
     }
     else if(rid<0)
     {
       cout<<"fai to sucess"<<endl;
     }
     else 
     {
       for(auto& e:v)
       {
         e();
       }
     }
  }  
}
